<template>
    <div class="table-box">
        <div class="table-search">
            <el-form :inline="true" :model="form">
                <!-- <el-form-item label="订单号	">
                    <el-input placeholder="订单号" v-model="form.order_no	"></el-input>
                </el-form-item> -->
                <el-form-item label="商户id">
                    <el-input placeholder="商户id" v-model="form.merchant_id"></el-input>
                </el-form-item>
                <el-form-item label="订单号">
                    <el-input placeholder="订单号" v-model="form.order_no"></el-input>
                </el-form-item>
                <!-- <el-form-item>
                    <el-input placeholder="设备ID">
                        <el-input placeholder="设备id" v-model="form.device_id"></el-input>
                    </el-input>
                </el-form-item> -->
                <!-- <el-form-item label="时间">
                    <el-date-picker v-model="form.timeData" type="datetimerange" range-separator="至"
                        start-placeholder="开始日期" end-placeholder="截止日期" />
                </el-form-item> -->
                <el-form-item>
                    <el-button type="primary" @click="onQuery">查询</el-button>
                    <el-button @click="onReset">重置</el-button>
                </el-form-item>
            </el-form>
            <!-- <div class="btn-box">
          <el-button type="primary" @click="onQuery">查询</el-button>
          <el-button @click="onReset">重置</el-button>
          <el-button type="primary" plain @click="onExport">导出</el-button>
        </div> -->
        </div>
        <div class="card content-box">
            <div class="table">
                <el-table :data="tableData" border v-loading="loading">
                    <el-table-column prop="id" label="ID" align="center" />
                    <el-table-column prop="merchant_id" label="商户id" align="center" />
                    <!-- <el-table-column prop="account_name" label="账号" align="center" /> -->
                    <el-table-column prop="order_no" label="订单号" align="center" />
                    <el-table-column prop="transaction_hash" label="交易hash" align="center" />
                    <el-table-column prop="transaction_index" label="交易下标" align="center" />
                    <el-table-column prop="block_height" label="区块高度" align="center" />
                    <el-table-column prop="from_address" label="转账地址" align="center" />
                    <el-table-column prop="block_hash" label="区块hash" align="center" />
                    <el-table-column prop="to_address" label="接收地址" align="center" />
                    <el-table-column prop="amount" label="金额" align="center" />

                    <el-table-column prop="token_symbol" label="token简称" align="center" />
                    <el-table-column prop="token_decimal" label="token精度" align="center" />
                    <el-table-column prop="confirmations" label="确认数" align="center" />
                    <!-- <el-table-column prop="status" label="订单状态" align="center" /> -->
                    <el-table-column prop="confirm_time" label="确认时间" align="center" :formatter="formatterTime" />
                    <!-- <el-table-column prop="expire_time" label="过期时间" align="center" :formatter="formatterTime" /> -->
                    <!-- <el-table-column prop="createtime" label="订单创建时间" align="center" :formatter="formatterTime" /> -->
                </el-table>
                <div class="table-pagination">
                    <el-pagination :current-page="pageable.pageNum" :page-size="pageable.pageSize"
                        :page-sizes="[10, 25, 50, 100]" :background="true" layout="total, sizes, prev, pager, next, jumper"
                        :total="pageable.total" @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"></el-pagination>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref, onMounted, reactive } from "vue";
import { formatterTime, timestamp } from "@/utils/utils";
import { usdtChainListApi } from "@/api/payServerse/payorder";
const loading = ref(false);

const tableData = ref([]);

// const loading = ref(false);

// const tableData = ref([]);
const formData = {
    channel_id: '',
    merchant_id: '',
    order_no: '',
    status: '',
    timeData: []
};
const form = reactive({ ...formData });

const pageable = reactive({
    pageNum: 1,
    pageSize: 20,
    total: 0
});

// 参数
const param = () => {
    return {
        order_no: form.order_no,
        status: form.status,
        channel_id: form.channel_id,
        merchant_id: form.merchant_id,
        start_time: form.timeData[0] ? timestamp(form.timeData[0].valueOf()) : "",
        end_time: form.timeData[1] ? timestamp(form.timeData[1].valueOf()) : "",
        page: pageable.pageNum,
        pagesize: pageable.pageSize
    };
};

// 获取表格数据
const getTbaleData = async () => {
    loading.value = true;

    try {
        const res = await usdtChainListApi(param());
        loading.value = false;
        tableData.value = res.data.results;
        pageable.total = res.data.count;
    } catch (error) {
        loading.value = false;
    }
};
//查询
const onQuery = async () => {
    getTbaleData();
};
// 重置
const onReset = () => {
    Object.assign(form, formData);
    getTbaleData();

};

// 条数
const handleSizeChange = number => {
    pageable.pageSize = number;
    getTbaleData();
};

// 页码
const handleCurrentChange = number => {
    pageable.pageNum = number;
    getTbaleData();
};
onMounted(() => {
    getTbaleData();
});
</script>
